package com.admin.web.controller;

import com.fegin.bean.admin.SystemInfo;
import com.util.WindowsInfoUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * @author 张子艺
 * @packge com.admin.controller
 * @data 2019-01-15 18:07
 * @project currencycloud
 */
@Controller
@RequestMapping("/admin/system")
public class SysTemController {

    /**
     * 欢迎页面
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/welcome.html", method = RequestMethod.GET)
    public Object login(HttpServletRequest request, HttpServletResponse response) throws IOException {
        return "system/welcome";
    }

    /**
     * 系统详情页面
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/system.html", method = RequestMethod.GET)
    public Object system(HttpServletRequest request, HttpServletResponse response)  {
        return "system/system";
    }


    /**
     * 系统详情
     */
    @RequestMapping(value = "/refeshSystem" )
    @ResponseBody
    public SystemInfo refeshSystem( Integer isShowCpu)  {
        SystemInfo systemInfo=new SystemInfo();
        //磁盘
        systemInfo.setDisk(WindowsInfoUtil.getDisk());
        //内存
        systemInfo.setMemery(WindowsInfoUtil.getMemery());
        //cpu
        if(isShowCpu>0){
          /*  double cpuNnum=CPUMonitorCalc.getInstance().getProcessCpu();
            int num=getInt(cpuNnum);
            systemInfo.setCpu( num);*/
        }
        return systemInfo;
    }

    public static int getInt(double number){
        BigDecimal bd=new BigDecimal(number).setScale(0, BigDecimal.ROUND_HALF_UP);
        return Integer.parseInt(bd.toString());
    }

}
